package com.pengtu.entity.app;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Where;

import com.pengtu.entity.IdEntity;

@Entity
@Table(name = "T_APP_MESSAGEINFO")
public class MessageInfo extends IdEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String type; //消息类型
	private String content; //消息内容
	private String subject;//主题
	private String sendFile;//附件
	private String sendUser;//发送者
	private String receiveUser;//接送者
	private Date sendDate;//发送时间
	private Date receiveDate;//阅读时间
	private String readFlag;//是否阅读
	private String grade;//消息级别
	private String remark;//备注
	private String receivedel;//阅读删除
	private String senddel;//发送删除
	
	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(
			new Comparator<Attachment>() {
				@Override
				public int compare(Attachment attFirst, Attachment attSecond) {
					// TODO Auto-generated method stub
					return attFirst.getCreateDate().compareTo(
							attSecond.getCreateDate());
				}
			}); // 附件

	@Column(name = "TYPE", length = 3)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "CONTENT", length = 2000)
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "SUBJECT", length = 200)
	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	@Column(name = "SENDFILE", length = 400)
	public String getSendFile() {
		return sendFile;
	}

	public void setSendFile(String sendFile) {
		this.sendFile = sendFile;
	}

	@Column(name = "SENDUSER", length = 48)
	public String getSendUser() {
		return sendUser;
	}

	public void setSendUser(String sendUser) {
		this.sendUser = sendUser;
	}

	@Column(name = "RECEIVEUSER", length = 48)
	public String getReceiveUser() {
		return receiveUser;
	}

	public void setReceiveUser(String receiveUser) {
		this.receiveUser = receiveUser;
	}

	@Column(name = "SENDDATE")
	public Date getSendDate() {
		return sendDate;
	}

	public void setSendDate(Date sendDate) {
		this.sendDate = sendDate;
	}

	@Column(name = "RECEIVEDATE")
	public Date getReceiveDate() {
		return receiveDate;
	}

	public void setReceiveDate(Date receiveDate) {
		this.receiveDate = receiveDate;
	}
	@Column(nullable = false,columnDefinition = "varchar2(3) default '0'",name="READFLAG")
	public String getReadFlag() {
		return readFlag;
	}

	public void setReadFlag(String readFlag) {
		this.readFlag = readFlag;
	}

	@Column(name = "GRADE")
	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	@Column(name = "REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@Column(nullable = false,columnDefinition = "varchar2(3) default '0'",name="RECEIVEDEL")
	public String getReceivedel() {
		return receivedel;
	}

	public void setReceivedel(String receivedel) {
		this.receivedel = receivedel;
	}

	@Column(nullable = false,columnDefinition = "varchar2(3) default '0'",name="SENDDEL")
	public String getSenddel() {
		return senddel;
	}

	public void setSenddel(String senddel) {
		this.senddel = senddel;
	}
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	@Where(clause="delFlag = 0")
	public Set<Attachment> getAttachmentSet() {
		return attachmentSet;
	}

	public void setAttachmentSet(Set<Attachment> attachmentSet) {

		this.attachmentSet = attachmentSet;
	}

	@Transient
	public Attachment getAttachment() {
		if (attachmentSet.iterator().hasNext())
			return attachmentSet.iterator().next();
		return new Attachment();
	}

	public void setAttachment(Attachment attachment) {
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}
	
}
